/*
 * @lc app=leetcode.cn id=111 lang=javascript
 *
 * [111] 二叉树的最小深度
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var minDepth = function(root) {
  let min = 0
  if (root === null) return 0
  let queque = [root]
  while (queque.length) {
    let n = queque.length
    min++
    for (let i = 0; i < n; i++){
      let cur = queque.shift()
      cur.left&&queque.push(cur.left)
      cur.right && queque.push(cur.right)
      if (!cur.left && !cur.right) {
        return min
       }
    }
  }
  return  min
};
// @lc code=end

